#switches for which EDXLSharp Tools (codeplex branch only) to include in the installer. Pure .dll tools are ignored
$includeHTTPLoader = $true
$includeRouterTool = $true
$includeIPAWSTester = $true


#enable this if you have a set of other tools to be deployed along with an IC.NET router install \ update
#they are copied over directly. At install time, files are overwritten if they already exist.
$includeOtherTools = $false
$otherToolsToInclude = "C:\otherToolsTest\*"  #end the path with a \* 

echo ""
echo "Starting to build the IC.NET Core Installer..."
echo ""

#Clear out the working directory and make a new temporary 'EDXLRouter' output folder
attrib -H /S /D
if(Test-Path EDXLRouter){del EDXLRouter -Recurse -Force}
#del 
del *.zip
md EDXLRouter | out-null;

#Copy the contents of the 'root' into EDXL. These files are 'static', they are just copied, not compiled.
cp root\* EDXLRouter\ -Recurse

#Copy the latest router code into the package, under the 'Update' folder.
#The idea is that all installs have a basic bootstrap level that is copied over and then updated to whatever the latest version is
$edxlRoot = "..\..\" #The top level of the EDXL Sharp codeplex repository (such as EDXLSharp-unstable)
$updatesDir = "EDXLRouter\bin\Updates\Deploy"

	# ICNETRest
	md $updatesDir\wwwroot
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\*.aspx $updatesDir\wwwroot\
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\*.png $updatesDir\wwwroot\
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\*.cs $updatesDir\wwwroot\
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\*.svc $updatesDir\wwwroot\
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\*.Master $updatesDir\wwwroot\
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\web.config $updatesDir\wwwroot\
	md $updatesDir\wwwroot\bin
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\bin\Release\*.* $updatesDir\wwwroot\bin
	md $updatesDir\wwwroot\Images
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\Images\*.* $updatesDir\wwwroot\Images
	md $updatesDir\wwwroot\Resources
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\Resources\*.* $updatesDir\wwwroot\Resources
	md $updatesDir\wwwroot\Scripts
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\Scripts\*.* $updatesDir\wwwroot\Scripts
	md $updatesDir\wwwroot\Styles
	Copy-Item $edxlRoot\EDXLSharp_Router\ICNETREST\Styles\* $updatesDir\wwwroot\Styles -Recurse
	md $updatesDir\wwwroot\XSLT
	cp $edxlRoot\EDXLSharp_Router\ICNETREST\XSLT\*.* $updatesDir\wwwroot\XSLT

	# Services
	md $updatesDir\wwwroot\DEProcessingService\Bin
	cp $edxlRoot\EDXLSharp_Router\DEProcessingSvc\bin\Release\*.* $updatesDir\wwwroot\DEProcessingService\Bin
	md $updatesDir\wwwroot\ExceptionService\Bin
	cp $edxlRoot\EDXLSharp_Router\ExceptionSvc\bin\Release\*.* $updatesDir\wwwroot\ExceptionService\Bin
	md $updatesDir\wwwroot\KeywordRoutingService\Bin
	cp $edxlRoot\EDXLSharp_Router\KeywordRoutingSvc\bin\Release\*.* $updatesDir\wwwroot\KeywordRoutingService\Bin
	md $updatesDir\wwwroot\FederationService\Bin
	cp $edxlRoot\EDXLSharp_Router\FederationSvc\bin\Release\*.* $updatesDir\wwwroot\FederationService\Bin
	md $updatesDir\wwwroot\DeadLetterService\Bin
	cp $edxlRoot\EDXLSharp_Router\DeadLetterSvc\bin\Release\*.* $updatesDir\wwwroot\DeadLetterService\Bin

	# Core
	md $updatesDir\ICNETCoreRouter
	cp $edxlRoot\EDXLSharp_Router\ICNETCoreRouter\bin\Release\*.* $updatesDir\ICNETCoreRouter

	# Config (Does not overwrite durring 'update' installs!)
	md $updatesDir\Config
	cp $edxlRoot\EDXLSharp_Router\ICNETServices\Config\*.* $updatesDir\Config -Force

	# Tools
	md $updatesDir\Tools
	if($includeHTTPLoader){
		md $updatesDir\HttpLoader
		cp $edxlRoot\EDXLSharp_Tools\HttpLoader\bin\Release\*.* $updatesDir\HttpLoader
	}

	if($includeRouterTool){
		md $updatesDir\RouterTool
		cp $edxlRoot\EDXLSharp_Tools\RouterTool\bin\Release\*.* $updatesDir\RouterTool
	}

	if($includeIPAWSTester){
		md $updatesDir\IPAWSTester
		cp $edxlRoot\EDXLSharp_Tools\IPAWSTester\bin\Release\*.* $updatesDir\IPAWSTester
	}

	if($includeOtherTools){
		cp $otherToolsToInclude $updatesDir\Tools -Recurse
	}








#zip up EDXLRouter
attrib -H /S /D #clear the read-only flag
[void][System.Reflection.Assembly]::LoadFrom((Get-Location).Path+"/Ionic.Zip.dll");
$zipfile =  new-object Ionic.Zip.ZipFile            
$e = $zipfile.AddDirectory((Get-Location).Path+"\EDXLRouter", "EDXLRouter")            
$zipfile.Save((Get-Location).Path+"\EDXLRouter.zip")            
$zipfile.Dispose()  


#clean up dir
attrib -H /S /D 
rm EDXLRouter -Recurse -Force

#rename the zip to have a timestamp built into the name
$dateString = (get-date).ToString();
$dateString = $dateString.Replace("/","-");
$dateString = $dateString.Replace(":",".");
$newZipName = "ICNET Router Installer "+$dateString+".zip"
move "EDXLRouter.zip" $newZipName

echo "Latest IC.NET Router Installer is now available at the path below:"
$finalPath = (pwd).Path
$finalPath = $finalPath+"\"+$newZipName
echo $finalPath

